#include <stdio.h>
#include "parser.h"
#include "generater.h"
#include "processor.h"

int
main (int argc, char *argv[]) {
    Parser *parser;
    Processor *proc;
    Generater *gen;
    Event *e;
   // FILE*log = fopen ("graph.log", "w+");
    // if (argc != 3) {
    //     fprintf (stderr, "usage:%s host_regex name_regex\n", argv[0]);
    //     exit (0);
    // }
    parser = optc_parser_create (stdin);
    if (parser == NULL) {
        fprintf (stderr, "Unable to create parser.\n");
        exit (EXIT_FAILURE);
    }
    proc = optc_processor_create ();
    if (proc == NULL) {
        fprintf (stderr, "Unable to create processor.\n");
        exit (EXIT_FAILURE);
    }
    gen = generater_create ();
    if (gen == NULL) {
        fprintf (stderr, "Unable to create generater.\n");
        exit (EXIT_FAILURE);
    }
    e = event_create ();
    guint i = 0;
    while (parser_parse (parser, e) == PARSER_INCOMING) {
        processor_process (proc, e);
        //event_output (e, stdout);
        //fflush (stdout);
        event_clear (e);
        i++;
    }
    fprintf (stderr, "process done\n");
    //event_destructor (e);
   // processor_traverse_all (proc, gen, default_gen);
    //processor_traverse_regex (proc, gen,argv[1], argv[2], "Process", TRUE, default_gen);
    // processor_traverse_regex_bidirectional (proc, gen,argv[1], argv[2], "Process", default_gen);
    //processor_traverse_regex_point2point (proc, gen, "201", "5452",  NULL,"660", "880", NULL, default_gen);
    processor_traverse_regex_point2point (proc, gen, "201", "5452",  NULL,"402", "3168", NULL, default_gen);
    generater_draw (gen, stdout);
    //processor_destructor (proc);
    //parser_destructor (parser);
    return 0;
}